import request from "@/utils/request";
import type { roleManeData } from "@/api/permission/roleMana/type";
import type { role, allGetType } from "@/api/permission/role/type";
enum API {
    // 获取全部数据
    GET_ALL_DATA = "/admin/acl/role/",
    // 新添职位
    ADD_OCCO = "/admin/acl/role/save",
    // 修改职位
    UPDATE_OCCO = "/admin/acl/role/update",
    // 根据角色获取权限
    GET_PERMISSION = "/admin/acl/permission/toAssign/",
    // 保存分配职位
    SAVE_PERMISSION = "/admin/acl/permission/doAssign/?",
    // 删除
    DELETE_ROLE = "/admin/acl/role/remove/",
}

export const getAllData = (page: number, limit: number, roleName: string) =>
    request.get<any, roleManeData>(
        API.GET_ALL_DATA + `${page}/${limit}/?username=${roleName}`
    );

export const occoMana = (data:role) => { 
    if (data.id) {
        return request.put<any, any>(API.UPDATE_OCCO, data);
    } else { 
        return request.post<any,any>(API.ADD_OCCO,data)
    }
}

export const getPermission = (roleId: number) =>
    request.get<any, allGetType>(API.GET_PERMISSION + roleId);

export const savePermission = (roleId: number, permissionId: any) =>
    request.post<any, any>(
        API.SAVE_PERMISSION + `roleId=${roleId}&permissionId=${permissionId}`
    );

export const deletRole = (id:number) => request.delete<any,any>(API.DELETE_ROLE+id)